package com.hanhanxiaochong.zhongxiangchuanmei.view.my.act;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.hanhanxiaochong.zhongxiangchuanmei.R;
import com.hanhanxiaochong.zhongxiangchuanmei.bean.CustomerDetailBean;
import com.hanhanxiaochong.zhongxiangchuanmei.config.HttpPostService;
import com.hanhanxiaochong.zhongxiangchuanmei.util.ResourcesUtils;
import com.hanhanxiaochong.zhongxiangchuanmei.util.SharedPreferencesUtil;
import com.hanhanxiaochong.zhongxiangchuanmei.view.base.BaseActivity;
import com.hanhanxiaochong.zhongxiangchuanmei.view.my.adapter.CustomerDetailAdapter;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.BaseObserver;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.Api.ResponseBase;
import com.wzgiceman.rxretrofitlibrary.retrofit_rx.http.RetrofitSource;

import butterknife.BindView;
import butterknife.OnClick;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

public class CustomerDetailActivity extends BaseActivity {

    @BindView(R.id.txt_title)
    TextView txtTitle;
    @BindView(R.id.customer_rv)
    RecyclerView customerRv;
    @BindView(R.id.tv_customer_name_phone)
    TextView tvCustomerNamePhone;

    private String token;
    private String customer_id;
    private String customer_name;
    private String customer_phone;

    public static Intent createIntent(Context context, String customer_id, String customer_name, String customer_phone) {
        Intent intent = new Intent(context, CustomerDetailActivity.class);
        intent.putExtra("customer_id", customer_id);
        intent.putExtra("customer_name", customer_name);
        intent.putExtra("customer_phone", customer_phone);
        return intent;
    }

    @Override
    protected void initView() {
        setContentView(R.layout.activity_customer_detail);
        token = SharedPreferencesUtil.getsInstances(this).getLoginInfo().getToken();
        Intent intent = getIntent();
        customer_id = intent.getStringExtra("customer_id");
        customer_name = intent.getStringExtra("customer_name");
        customer_phone = intent.getStringExtra("customer_phone");
    }

    @Override
    protected void initPresenter() {

    }

    @Override
    protected void init() {
        txtTitle.setText("顾客详情");
        customerRv.setLayoutManager(new LinearLayoutManager(this));
        RetrofitSource.createApi(HttpPostService.class)
                .tech_user_list(token, customer_id, customer_name, customer_phone)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<ResponseBase<CustomerDetailBean>>(this) {
                    @Override
                    public void onSuccess(ResponseBase<CustomerDetailBean> response) {
                        CustomerDetailBean bean = response.getData();
                        tvCustomerNamePhone.setText(String.format(ResourcesUtils.getString(R.string.customer_name_phone),
                                bean.getUser_nicename(), bean.getMobile()));
                        CustomerDetailAdapter adapter =
                                new CustomerDetailAdapter(CustomerDetailActivity.this, R.layout.item_tech_order, bean.getList());
                        customerRv.setAdapter(adapter);
                    }
                });
    }

    @OnClick(R.id.ll_leftview)
    public void onViewClicked() {
        finish();
    }

}
